package dtaskboard.server;

import java.util.HashMap;
import java.util.Map;

import dtaskboard.entities.User;

public final class SessionManager {

  private static SessionManager instance;

  private final Map<String, User> sessions;

  private SessionManager() {
    this.sessions = new HashMap<String, User>();
  }

  public static SessionManager get() {
    if (SessionManager.instance == null) {
      SessionManager.instance = new SessionManager();
    }
    return SessionManager.instance;
  }

  public User userId(String sessionId) {
    return this.sessions.get(sessionId);
  }

  public void add(User user, String sessionId) {
    this.sessions.put(sessionId, user);
  }

  public void clean(String sessionId) {
    this.sessions.remove(sessionId);
  }
}
